home *** CD-ROM | disk | FTP | other *** search
Text File | 2003-07-17 | 38.4 KB | 1,472 lines |
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: December 9, 1996
- //
- // Description:
- // File Browser.
- //
- // Input Arguments:
- // String Callback on OK action
- // String action name for button and window title
- // String The type of file requested.
- // Int The browser mode.
- // 0 for read.
- // 1 for write. (export)
- // 2 for write without paths. (file save)
- // 4 directories have meaning when used with the
- // action button.
- //
- //
- // Globals that may be used:
- // $gDefaultFileBrowserDir - If not "" then the file options
- // for default Dir will take you to the
- // directory specified.
- //
- // Return Value:
- // Done through the callback provided. The callback has the following
- // parameters:
- // String The file specified by the user.
- // String The type of file specified by the user.
- //
- // If the user wishes to provide more parameters to the callback they
- // may do so providing that the last two parameters are the ones given
- // above.
- //
- // The callback returns true if the window should be removed when
- // done.
- //
- // Eg.
- // myCallBack myParam1 myParam2 filePath fileType
- //
-
-
- //
- // Globals used by the browser.
- //
- global string $gv_CallBackCommand;
- global int $gv_displayMode;
- global int $gv_displayHiddenMode;
- global int $gv_browserMode; // 0 for read, 1 for write.
-
- global string $gDefaultFileBrowserDir = "";
-
- //
- // Menus.
- //
-
- global proc sv_FileMenuProjects (string $parent)
- //
- // Description:
- // Build the File menu for the file browser.
- // The first items of this menu are static and allow the
- // user to move to specific directories quickly. The
- // second set of items are built dynamically and show
- // the projects that the user has created.
- //
- // Input Arguments:
- // The parent control that menu will be created in.
- //
- // Return Value:
- // None.
- //
- {
- global string $gDefaultFileBrowserDir;
- global int $gv_browserMode;
-
- string $currentProject = `workspace -q -rd`;
- if ( size( $currentProject ) > 0 )
- $projectsDir = dirname( $currentProject ) + "/";
- else
- $projectsDir = `internalVar -uad`+"projects/";
- string $scenesDir = $currentProject + `workspace -q -ote "scene"`;
- string $homeDir = `getenv "HOME"`;
- string $defaultDir;
- if ($gDefaultFileBrowserDir != "") {
- $defaultDir = $gDefaultFileBrowserDir;
- } else {
- $defaultDir = `workspace -q -dir`;
- }
-
- // Rebuild the projects menu items.
-
- // Remove the old menu items
- //
- menu -e -deleteAllItems $parent;
-
- // Build the static items
- //
-
- // We want to allow jumping to the project dialog from the
- // file dialog - a value of 4 means that they're already in
- // the project dialog (so we don't want the menu there!)
- if ( $gv_browserMode != 4 )
- {
- menuItem -p $parent -l "Set Project"
- -c "setProject \"\"";
-
- menuItem -p $parent -d true;
- }
-
- menuItem -p $parent -l "Go to Current Project"
- -c "pv_goCurrentProject";
-
- menuItem -p $parent -l "Go to Current scenes"
- -c ("pv_goDirectory \""+$scenesDir+"\"") scenesItem;
-
- menuItem -p $parent -l "Go to Home"
- -c ("pv_goDirectory \""+$homeDir+"\"");
-
- menuItem -p $parent -l "Go to Projects"
- -c ("pv_goDirectory \""+$projectsDir+"\"") projectsItem;
-
- menuItem -p $parent -l "Go to Default"
- -c ("pv_goDirectory \""+$defaultDir+"\"") defaultItem;
-
-
- // If $dirStat == 0 then either 'stat' doesn't exist or
- // failed somehow so don't try to build the dynamic items
- // or we'll end up building them on every menu access which
- // will be very slow.
- //
-
- // Stick in a divider line
- //
- menuItem -p $parent -d true;
-
- // Build the dynamic items
- //
-
- string $listOfFiles[] = `workspace -l $projectsDir`;
-
- string $cmd;
- string $aDir;
- string $testDir;
- string $fileType[];
-
- for ($aDir in $listOfFiles) {
- $testDir = $projectsDir+$aDir;
-
- $fileType = `file -q -type $testDir`;
-
- if (size($fileType) > 0 && "directory" == $fileType[0]) {
- $cmd = "pv_goDirectory \""+$testDir+"\"";
- menuItem -p $parent -l $aDir -c $cmd;
- }
- }
- }
-
- global proc int sv_FileMenu (string $parent)
- //
- // Description:
- // This is the popup menu for the project file viewer pane.
- //
- {
- menu -p $parent -l "File"
- -pmc "sv_FileMenuProjects \"projectViewerFileMenu\""
- projectViewerFileMenu;
-
- return 1;
- }
-
- proc int sv_ViewMenu ( string $parent )
- {
- global int $gv_displayHiddenMode;
-
- // The View Menu.
- menu -p $parent -l "View" viewMenu;
- radioMenuItemCollection viewerMenuCluster;
- menuItem -l "as Text" -rb false -c ("pv_setDisplayMode 10") textListItem;
- menuItem -l "as Icons" -rb false -c ("pv_setDisplayMode 0") iconListItem;
- // menuItem -l "as Small Icons" -rb false -c ("pv_setDisplayMode 1") smallIconListItem;
- // menuItem -l "as References" -rb false -c ("pv_setDisplayMode 2") referencedListItem;
-
- setParent -m viewMenu;
- menuItem -d true;
- menuItem
- -l "Display Hidden Files"
- -cb $gv_displayHiddenMode
- -c ("pv_setDisplayHiddenMode") displayHiddenItem;
-
- return 1;
- }
-
- proc int sv_SortMenu ( string $parent )
- {
- string $sortByMode;
-
- if (!`optionVar -ex fileBrowserSortMode`) {
- optionVar -sv fileBrowserSortMode "name";
- }
- $sortByMode = `optionVar -q fileBrowserSortMode`;
-
- // The Sort Menu.
- menu -p $parent -l "Sort" sortMenu;
- radioMenuItemCollection sortMenuCluster;
- menuItem -l "by Name" -rb true -c ("pv_setSortMode name") sortByNameItem;
- menuItem -l "by Date" -rb false -c ("pv_setSortMode date") sortByDateItem;
- menuItem -l "by Size" -rb false -c ("pv_setSortMode size") sortBySizeItem;
-
- switch ($sortByMode) {
- case "date":
- menuItem -e -rb on ($parent+"|sortMenu|sortByDateItem");
- break;
- case "size":
- menuItem -e -rb on ($parent+"|sortMenu|sortBySizeItem");
- break;
- default:
- // Do nothing as name is already selected.
- //
- break;
- }
- return 1;
- }
-
- global proc buildFileContextHelpItems(string $nameRoot, string $menuParent)
- //
- // Description:
- // Build context sensitive menu items for this window.
- //
- // Input Arguments:
- // $nameRoot - name to use as the root of all item names
- // $menuParent - the name of the parent of this menu
- //
- // Return Value:
- // None
- //
- {
- menuItem -label "Help on File Browser..."
- -enableCommandRepeat false
- -command "showHelp FileBrowser";
- }
-
- global proc int sv_Menu ( string $windowName )
- //
- // Description:
- // Create the menus
- //
- {
- sv_FileMenu $windowName;
- sv_ViewMenu $windowName;
- sv_SortMenu $windowName;
-
- // One more menu to bring up the option box
- //
- menu -p $windowName -l "Options" fileOptionsMenu;
- menuItem fileOptionsMenuItem;
-
- // Add support for the Context Sensitive Help Menu.
- //
- addContextHelpProc $windowName "buildFileContextHelpItems";
- doHelpMenu($windowName, $windowName);
-
- return 1;
- }
-
-
- // Callback procs.
- //
-
-
- global proc pv_redrawView ( )
- //
- // Description:
- // redraw the view of the current workspace for the top
- // viewing tab.
- //
- {
- global int $gv_displayMode;
- global string $gv_wsFinder;
-
- string $topTabName;
- int $wsIndex;
-
- string $workspaceList[]; // Replacing -lfw with -fn. -rams
- $str = `workspace -q -fn`;
- $workspaceList[0] = $str;
-
- string $theWorkspace;
- string $wsViewerForm;
- string $projectPath;
- string $curPath;
-
- $wsViewerForm = `tabLayout -q -st workspaceTabs`;
-
- $wsIndex = `tabLayout -q -sti workspaceTabs`;
- $wsIndex = $wsIndex - 1; // Make it 0 based for WS index.
-
- $theWorkspace = $workspaceList[$wsIndex];
-
- workspace -u $theWorkspace; // Update the workspace cache.
-
- $projectPath = `workspace -q -dir $theWorkspace`;
- $curPath = `finder -q -fp $gv_wsFinder`;
- if ($curPath != $projectPath) {
- // This is an expensive operation.
- finder -e -fp $projectPath $gv_wsFinder;
- }
-
- // Create the appropriate viewer if we don't already have it.
-
- switch ($gv_displayMode) {
- case 0 : // Large Icon View
- pv_projIconViewer ( $wsViewerForm, $wsIndex, $theWorkspace);
- menuItem -e -rb true iconListItem;
- break;
- case 1 : // Small Icon View
- // pv_projSmallIconViewer ( $wsViewerForm, $wsIndex, $theWorkspace);
- // menuItem -e -rb true smallIconListItem;
- // break;
- case 2 : // Reference View
- // pv_projRefViewer ( $wsViewerForm, $wsIndex, $theWorkspace);
- // menuItem -e -rb true referencedListItem;
- // break;
- case 3 : // Setup View
- // menuItem -e -rb true viewWorkspaceEdit;
- break;
- case 10 : // Text (default) View
- default :
- menuItem -e -rb true textListItem;
- pv_projTextViewer ( $wsViewerForm, $wsIndex, $theWorkspace);
- break;
- }
-
- }
-
- global proc pv_setSortMode( string $mode )
- //
- // The user has changed the sort method. Update the viewer.
- //
- {
- string $wsViewerForm;
- string $wsViewerName[2];
- $wsViewerForm = `tabLayout -q -st workspaceTabs`;
- $wsViewerName = `formLayout -q -ca $wsViewerForm`;
-
- projFileViewer -e -sortBy $mode $wsViewerName[0];
-
- optionVar -sv fileBrowserSortMode $mode;
- }
-
-
- global proc pv_setDisplayMode ( int $mode )
- //
- // Description:
- // Set the display mode to the given mode.
- //
- {
- global int $gv_displayMode;
-
- $gv_displayMode = $mode;
-
- optionVar -iv fileBrowserDisplayMode $gv_displayMode;
-
- pv_redrawView;
- }
-
-
- global proc pv_setDisplayHiddenMode ( )
- //
- // Description:
- // Set or clear the flag to display hidden files.
- //
- //
- {
- global int $gv_displayHiddenMode;
- string $wsViewerForm;
- string $wsViewerName[2];
-
- $wsViewerForm = `tabLayout -q -st workspaceTabs`;
- $wsViewerName = `formLayout -q -ca $wsViewerForm`;
-
- int $mode = `menuItem -q -cb displayHiddenItem`;
-
- // projFileViewer -e -displayHidden $mode $wsViewerName[0];
-
- optionVar -iv fileBrowserDisplayHiddenMode $mode;
- $gv_displayHiddenMode = $mode;
-
- pv_redrawView;
- }
-
-
- global proc int sv_newFileType ( )
- //
- // Description:
- // This is the callback for the file type list.
- //
- {
- return 1;
- }
-
-
- global proc int pv_doubleClickAction ( int $filterDirs )
- //
- // Description:
- // open the selected item.
- //
- // Parameters:
- // $filterDirs - 1 if directories should be used to navigate.
- // - 0 if directories have meaning.
- //
- {
- global string $gv_CallBackCommand;
- global string $gv_wsFinder;
- global string $gv_operationMode;
- global int $gv_browserMode;
-
- string $fileType;
- string $thePath;
- string $newPath;
- int $wsIndex;
- string $theWorkspace;
- string $workspaceList[];
- int $status;
- string $realType[];
-
- $thePath = `finder -q -fp $gv_wsFinder`;
-
- // Maybe the user has entered in some ~'s or env vars by hand-
- // this expandName call expands those out (we only want to reset
- // the finder if the path's really changed though)
- $newPath = `file -q -expandName $thePath`;
- if ( $newPath != $thePath )
- {
- $thePath = $newPath;
- finder -e -fp $thePath $gv_wsFinder;
- }
-
- if ($thePath == "") {
- $thePath = "/"; // Then it must be the root.
- finder -e -fp $thePath $gv_wsFinder;
- }
-
- int $index = `optionMenu -q -select fileTypePopList`;
-
- string $typeList[] = `optionMenu -q -ils fileTypePopList`;
- $fileType = `menuItem -q -l $typeList[$index-1]`;
- if (`file -q -ex $thePath`) {
- $realType = `file -q -typ $thePath`;
- }
-
- int $renderGlobalsFileType = `getAttr defaultRenderGlobals.outf`;
- int $resetRenderGlobalsFileType = true;
- if ($fileType == "Best Guess") {
- $resetRenderGlobalsFileType = false;
-
- // If Any then ask the file for its real type.
- int $numTrans = size($realType);
- int $index;
- if ($numTrans > 0) {
- for ($index = 0; $index < $numTrans; $index++) {
- switch ($gv_browserMode) {
- case 0 : // Read mode.
- case 4 :
- if (`translator -q -rs $realType[$index]`) {
- $fileType = $realType[$index];
- $index = $numTrans;
- }
- break;
- case 1 : // Write mode.
- case 2 :
- if (`translator -q -ws $realType[$index]`) {
- $fileType = $realType[$index];
- $index = $numTrans;
- }
- break;
- }
- }
- } else {
- $fileType = "Best Guess";
- }
- } else if ($fileType == "Maya IFF (iff)") {
- setAttr defaultRenderGlobals.outf 7;
- } else if ($fileType == "Alias PIX (als)") {
- setAttr defaultRenderGlobals.outf 6;
- } else if ($fileType == "Cineon (cin)") {
- setAttr defaultRenderGlobals.outf 11;
- } else if ($fileType == "EPS (eps)") {
- setAttr defaultRenderGlobals.outf 9;
- } else if ($fileType == "GIF (gif)") {
- setAttr defaultRenderGlobals.outf 0;
- } else if ($fileType == "JPEG (jpg)") {
- setAttr defaultRenderGlobals.outf 8;
- } else if ($fileType == "Quantel (yuv)") {
- setAttr defaultRenderGlobals.outf 12;
- } else if ($fileType == "RLA (rla)") {
- setAttr defaultRenderGlobals.outf 2;
- } else if ($fileType == "SGI (sgi)") {
- setAttr defaultRenderGlobals.outf 5;
- } else if ($fileType == "SoftImage (pic)") {
- setAttr defaultRenderGlobals.outf 1;
- } else if ($fileType == "Targa (tga)") {
- setAttr defaultRenderGlobals.outf 19;
- } else if ($fileType == "Tiff (tif)") {
- setAttr defaultRenderGlobals.outf 3;
- } else if ($fileType == "Windows Bitmap (bmp)") {
- setAttr defaultRenderGlobals.outf 20;
- } else {
- $resetRenderGlobalsFileType = false;
- }
-
- if ($filterDirs == 1 && size($realType) > 0 && $realType[0] == "directory") {
- // Then we have a path.
- $wsIndex = `tabLayout -q -sti workspaceTabs`;
- $wsIndex = $wsIndex - 1; // Make it 0 based for WS index.
-
- $str = `workspace -q -fn`; // Replacing -lfw with -fn. -rams
- $workspaceList[0] = $str;
- $theWorkspace = $workspaceList[$wsIndex];
-
- workspace -dir $thePath $theWorkspace;
-
- // Fix the sound/image buttons
- button -e -enable false pv_viewImageButton;
- button -e -enable false pv_playSoundButton;
-
- pv_redrawView; // refresh the view.
- $status = false;
- } else {
- $status = eval($gv_CallBackCommand+" \""+$thePath+"\" \""+$fileType+"\"");
- }
-
- // reset output image format.
- if ($resetRenderGlobalsFileType)
- setAttr defaultRenderGlobals.outf ($renderGlobalsFileType);
-
- if ($status) {
- // The action completed successfully.
- window -e -vis false projectViewerWindow;
- $gv_operationMode = "";
- }
-
- return 1;
- }
-
- proc pv_setMenuFileType ( string $newType, int $setup )
- //
- // Description:
- // set the select menu type in the fileTypePopList
- // to the type given.
- //
- {
- global int $gv_browserMode;
- int $numTypes;
- string $typeList[];
- string $qFileType;
-
- // Show the user what the file type is
- //
- text -edit -l $newType fileTypeFeedback;
-
- if ($setup || ($gv_browserMode != 1 && $gv_browserMode != 2)) {
- // Don't change the type if we are writing the file.
-
- // Change the popup to be the closest file type to
- // what can actually be read/written
- //
- $numTypes = `optionMenu -q -ni fileTypePopList`;
- $typeList = `optionMenu -q -ils fileTypePopList`;
- for ($index = 0; $index < $numTypes; $index++) {
- $qFileType = `menuItem -q -l $typeList[$index]`;
- if ($qFileType == $newType) {
- optionMenu -e -select ($index+1) fileTypePopList;
- sv_newFileType;
- break;
- }
- }
- if ($index == $numTypes) {
- // Make it type any since the type is unknown.
- optionMenu -e -select 1 fileTypePopList;
- sv_newFileType;
- }
- }
-
- }
-
- global proc pv_viewImage( string $filename )
- {
- waitCursor -state on;
- string $fcheckCmd = "fcheck \"" + $filename + "\" 2>&1";
- string $fcheckReturn = `system( $fcheckCmd )`;
-
- if ( match( "Unknown image format", $fcheckReturn ) != "" )
- {
- confirmDialog -button OK -db OK -message
- "Display of this type of image is not supported";
- }
- waitCursor -state off;
- }
-
- global proc int pv_selectCmd ( )
- //
- // Description:
- // a single click was recieve so a selection is being performed.
- // Update information appropriate to the select.
- //
- {
- global int $gv_displayMode;
- global string $gv_wsFinder;
- global int $gv_browserMode;
-
- // Set the finder text to the selected item name.
- string $selectedItem[];
- string $currentItem;
- string $fileType;
- int $numTypes;
- string $typeList[];
- string $qFileType;
- string $workspaceList[];
- int $wsIndex;
- string $wsViewerForm;
- string $wsViewerName[];
- string $theWorkspace;
- string $fileTypeList[];
-
- $str = `workspace -q -fn`; // Replacing -lfw with -fn. -rams
- $workspaceList[0] = $str;
-
- $wsViewerForm = `tabLayout -q -st workspaceTabs`;
- $wsViewerName = `formLayout -q -ca $wsViewerForm`;
-
- $wsIndex = `tabLayout -q -sti workspaceTabs`;
- $wsIndex = $wsIndex - 1; // Make it 0 based for WS index.
-
- $theWorkspace = $workspaceList[$wsIndex];
-
- // Get the selected Item.
- switch ($gv_displayMode) {
- case 0 : // Large Icon View
- case 1 : // Small Icon View
- case 3 : // Setup View
- case 10 : // Text (default) View
- default :
- $selectedItem = `projFileViewer -q -si $wsViewerName[0]`;
- break;
- }
-
- // Now make the new workspace active.
- // workspace -act $theWorkspace;
-
- $currentItem = `workspace -q -dir $theWorkspace`;
-
- if (match("/$", $currentItem) != "/" && match("^/", $selectedItem[0]) != "/") {
- $currentItem = $currentItem + "/" + $selectedItem[0];
- } else {
- $currentItem = $currentItem + $selectedItem[0];
- }
-
- finder -e -fp $currentItem $gv_wsFinder;
-
- $fileTypeList = `file -q -typ $currentItem`;
- int $numTrans = size($fileTypeList);
- int $index;
- if ($numTrans > 0) {
- for ($index = 0; $index < $numTrans; $index++) {
- switch ($gv_browserMode) {
- case 0 : // Read mode.
- case 4 :
- if (`translator -q -rs $fileTypeList[$index]`) {
- $fileType = $fileTypeList[$index];
- $index = $numTrans;
- }
- break;
- case 1 : // Write mode.
- case 2 :
- if (`translator -q -ws $fileTypeList[$index]`) {
- $fileType = $fileTypeList[$index];
- $index = $numTrans;
- }
- break;
- }
- }
- } else {
- $fileType = "Best Guess";
- }
-
- // A file was selected so indicate the type.
- pv_setMenuFileType($fileType, 0);
-
- // Enable/disable the view image button based
- // on the selected type
- //
- string $cmd = "pv_viewImage \"" + $currentItem + "\"";
- button -e
- -command $cmd
- -enable ($fileType == "image") pv_viewImageButton;
-
- if (`about -evalVersion`)
- {
- // The evaluation version of Maya cannot use the system
- // command so it cannot play sounds. Just make sure that
- // $fileType != audio so it will not try.
- //
- if ($fileType == "audio")
- {
- // Make a change that will invalidate the test below but
- // (hopefully) not confuse any humans who may be looking
- // at the value.
- //
- $fileType = "AUDIO";
- }
- }
-
- // Enable/disable the play sound button based
- // on the selected type
- //
- string $cmd = ( "waitCursor -state on; " );
- $cmd = $cmd + ( "system( \"soundplayer " + $currentItem + "\"); " );
- $cmd = $cmd + ( "waitCursor -state off; " );
- button -e
- -command $cmd
- -enable ($fileType == "audio") pv_playSoundButton;
-
- return 1;
- }
-
- global proc pv_selectTab ( )
- //
- // Description:
- // This callback in invoked when a viewer tab is selected.
- //
- {
- global int $gv_displayMode;
- string $selectedItem[];
- int $numSelected;
- string $wsViewerForm;
- string $wsViewerName[];
- int $index;
-
- pv_redrawView; // refresh the view.
-
- $wsViewerForm = `tabLayout -q -st workspaceTabs`;
- $wsViewerName = `formLayout -q -ca $wsViewerForm`;
-
- switch ($gv_displayMode) {
- case 0 : // Large Icon View
- case 1 : // Small Icon View
- case 3 : // Setup View
- case 10 : // Text (default) View
- default :
- $numSelected = `projFileViewer -q -nsi $wsViewerName[0]`;
- $selectedItem = `projFileViewer -q -si $wsViewerName[0]`;
- for ($index = 0; $index < $numSelected; $index++) {
- projFileViewer -e -di $selectedItem[$index] $wsViewerName[0];
- }
- break;
- }
-
- }
-
- global proc int pv_goDirectory (string $dirPath)
- //
- // Description:
- // Change the workspace directory to the given path
- //
- {
- if ($dirPath == "") {
- error ("Invalid directory path specified");
- return 0;
- } else {
- workspace -dir $dirPath;
- pv_redrawView;
- return 1;
- }
- }
-
- global proc int pv_goCurrentProject ()
- //
- // Description:
- // return back to the root directory for this workspace.
- //
- {
- workspace -dir `workspace -q -rd`;
- pv_redrawView;
-
- return 1;
- }
-
-
- proc int pv_projViewer (int $mode, string $theParent, int $wsIndex, string $wsPath )
- //
- // Description:
- // Common functionality for text/icon views.
- //
- {
- string $argList;
- string $wsFullName;
- string $viewerName = ("wsIconViewer"+$wsIndex);
- string $oldViewerName[];
- string $callBacks[];
- string $sortByMode;
- global int $gv_displayHiddenMode;
-
-
- $wsFullName = `workspace -q -fn $wsPath`;
- $argList = ("\""+ $wsFullName+"\" "+$wsIndex);
- $callBacks[0] = ("pv_selectCmd");
- $callBacks[1] = ("pv_doubleClickAction 1");
-
- if (!`optionVar -ex fileBrowserSortMode`) {
- optionVar -sv fileBrowserSortMode "name";
- }
- $sortByMode = `optionVar -q fileBrowserSortMode`;
-
- setParent $theParent;
- if (!`projFileViewer -ex $viewerName`) {
- $oldViewerName = `formLayout -q -ca $theParent`;
- if (size($oldViewerName) > 0) deleteUI $oldViewerName[0];
-
- projFileViewer -ws $wsFullName -dm $mode
- -sc $callBacks[0]
- -dcc $callBacks[1]
- -sortBy $sortByMode
- -dh $gv_displayHiddenMode
- $viewerName;
- formLayout -e -af $viewerName "left" 0 -af $viewerName "right" 0
- -af $viewerName "top" 0 -af $viewerName "bottom" 0
- $theParent;
- } else {
- if ($mode != `projFileViewer -q -dm $viewerName`) {
- projFileViewer -e -dm $mode $viewerName; // Could be layout change.
- }
-
- if ($sortByMode != `projFileViewer -q -sortBy $viewerName`) {
- projFileViewer -e -sortBy $sortByMode $viewerName;
- }
-
- if ($gv_displayHiddenMode != `projFileViewer -q -dh $viewerName`) {
- projFileViewer -e -dh $gv_displayHiddenMode $viewerName;
- }
- }
-
- projFileViewer -e -fr $viewerName;
-
- return 1;
- }
-
- global proc int pv_projIconViewer ( string $theParent, int $wsIndex, string $wsPath )
- //
- // Description:
- // setup all the callbacks and create the icon viewer.
- //
- {
- global int $gv_displayMode;
-
- $gv_displayMode = 0;
- optionVar -iv fileBrowserDisplayMode $gv_displayMode;
-
- return pv_projViewer(1, $theParent, $wsIndex, $wsPath);
- }
-
- global proc int pv_projSmallIconViewer ( string $theParent, int $wsIndex, string $wsPath )
- //
- // Description:
- // setup all the callbacks and create the icon viewer.
- //
- {
- global int $gv_displayMode;
-
- $gv_displayMode = 1;
- optionVar -iv fileBrowserDisplayMode $gv_displayMode;
-
- return pv_projViewer(2, $theParent, $wsIndex, $wsPath);
- }
-
- global proc int pv_projTextViewer ( string $theParent, int $wsIndex, string $wsPath )
- //
- // Description:
- // setup all the callbacks and create the icon viewer.
- //
- {
- global int $gv_displayMode;
-
- $gv_displayMode = 10;
- optionVar -iv fileBrowserDisplayMode $gv_displayMode;
-
- return pv_projViewer(0, $theParent, $wsIndex, $wsPath);
- }
-
-
- global proc int pv_resetWorkspace ( )
- //
- // Description:
- // The window is already created but for some reason our workspaces have
- // changed. Update the information.
- //
- {
- int $index;
- int $numWS;
- string $workspaces[];
- string $workspacePaths[];
- string $allTabs[];
- int $viewMode;
- string $wsViewerForm;
- string $viewerName[];
-
- // Replacing -lw & -lfw with -sn & -fn. -rams
- //
- $str = `workspace -q -sn`; // Get workspace short names.
- $workspaces[0] = $str;
- $str = `workspace -q -fn`; // Get workspace full names.
- $workspacePaths[0] = $str;
-
- $numWS = size($workspaces);
-
- $allTabs = `tabLayout -q -ca workspaceTabs`;
-
- for ($index = 0; $index < $numWS; $index++) {
- $wsViewerForm = "wsViewerForm"+$index;
-
- if (!`formLayout -ex $wsViewerForm`) {
- setParent workspaceTabs;
- formLayout $wsViewerForm;
- } else {
- // Clear out the old information.
- $viewerName = `formLayout -q -ca $wsViewerForm`;
- if (size($viewerName) > 0) deleteUI $viewerName[0];
- }
- tabLayout -e -tl $wsViewerForm $workspaces[$index] workspaceTabs;
- }
-
-
- // Remove unused tabs.
-
- if (size($allTabs) > ($numWS)) {
- for ($index = $numWS; $index < size($allTabs); $index++) {
- deleteUI $allTabs[$index]; // Remove tab.
- }
- }
-
- pv_redrawView();
-
- return 1;
- }
-
-
- proc buildControlArea ( string $parent )
- {
- global int $gv_browserMode;
- global string $gv_wsFinder = "wsFinder0";
-
- setParent $parent;
-
- string $workspacePath = `workspace -q -fn`;
- finder -adr false -c ("pv_doubleClickAction 1")
- -fp $workspacePath $gv_wsFinder;
-
- button -align "center" actionOK;
-
- // Create buttons to see image files and hear sound files
-
- button -l "See Image" -align "center"
- -enable false
- -c "" pv_viewImageButton;
-
- button -l "Hear Sound" -align "center"
- -enable false
- -c "" pv_playSoundButton;
-
- button -l "Cancel" -align "center"
- -c ("{global string $gv_operationMode;"
- + "$gv_operationMode = \"\";"
- + "window -e -vis false projectViewerWindow;}") saveFileCancel;
-
- formLayout -e
- -af $gv_wsFinder "top" 0
- -af $gv_wsFinder "left" 0
- -af $gv_wsFinder "right" 0
- -ac $gv_wsFinder "bottom" 0 actionOK
-
- -an actionOK "top"
- -af actionOK "left" 5
- -ap actionOK "right" 3 25
- -af actionOK "bottom" 5
-
- -an pv_viewImageButton "top"
- -ap pv_viewImageButton "left" 2 25
- -ap pv_viewImageButton "right" 3 50
- -af pv_viewImageButton "bottom" 5
-
- -an pv_playSoundButton "top"
- -ap pv_playSoundButton "left" 2 50
- -ap pv_playSoundButton "right" 3 75
- -af pv_playSoundButton "bottom" 5
-
- -an saveFileCancel "top"
- -ap saveFileCancel "left" 2 75
- -af saveFileCancel "right" 5
- -af saveFileCancel "bottom" 5
- controlArea;
-
- }
-
- // Pretty useless now, but maybe we'll expand
- // the image translators...
- proc string[] getImageTranslators()
- {
- string $translators[];
- string $retArray[];
- int $count, $i, $j = 0;
-
- $translators = `translator -q -l`;
- $count = size( $translators );
-
- for ( $i = 0; $i < $count; $i++ )
- {
- if ( $translators[$i] == "image" )
- {
- $retArray[$j] = $translators[$i];
- $j++;
- }
- }
-
- return $retArray;
- }
-
- proc buildFileTypeMenu( int $mode, string $type )
- {
- string $fileTypes[];
- int $count;
- int $index;
-
- // Directory browser
- if ( $mode == 4 )
- {
- menuItem -l "directory" "DirectoryTypeMenu";
- return;
- }
-
- if ( $type == "image" && $mode != 0 )
- {
- menuItem -l "Maya IFF (iff)" iffTypeMenu;
- menuItem -l "Alias PIX (als)" aliasPIXTypeMenu;
- menuItem -l "Cineon (cin)" cineonTypeMenu;
- menuItem -l "EPS (eps)" epsTypeMenu;
- menuItem -l "GIF (gif)" gifTypeMenu;
- menuItem -l "JPEG (jpg)" jpegTypeMenu;
- menuItem -l "Quantel (yuv)" quantelTypeMenu;
- menuItem -l "RLA (rla)" rlaTypeMenu;
- menuItem -l "SGI (sgi)" sgiTypeMenu;
- menuItem -l "SoftImage (pic)" softImageTypeMenu;
- menuItem -l "Targa (tga)" targaTypeMenu;
- menuItem -l "Tiff (tif)" tiffTypeMenu;
- menuItem -l "Windows Bitmap (bmp)" bitmapTypeMenu;
- return;
- }
-
- if ( $type == "map" && $mode != 0 )
- {
- menuItem -l "From Tool Settings" ToolSettingsTypeMenu;
- return;
- }
-
- if ( $type == "mel" )
- {
- menuItem -l "mel" melfileTypeMenu;
- return;
- }
-
- // If iff is specified, we'll guess that that's the only
- // type supported (otherwise "image" should have been passed
- // as the type)
- if ( $type == "iff" )
- {
- menuItem -l "iff" ifffileTypeMenu;
- return;
- }
-
- if ( $type == "image" || $type == "map" )
- {
- $fileTypes = getImageTranslators();
- $count = size( $fileTypes );
- for ( $index = 0; $index < $count; $index ++ )
- {
- menuItem -l $fileTypes[$index]
- ($fileTypes[$index]+"fileTypeMenu");
- }
- return;
- }
-
- $fileTypes = `translator -q -l`;
- $count = size($fileTypes);
- for ($index = 0; $index < $count; $index++)
- {
- switch ($mode)
- {
- case 0 : // Read mode.
- if (`translator -q -rs $fileTypes[$index]`) {
- menuItem -l $fileTypes[$index]
- ($fileTypes[$index]+"fileTypeMenu");
- }
- break;
- case 1 : // Write mode.
- if (`translator -q -ws $fileTypes[$index]`) {
- menuItem -l $fileTypes[$index]
- ($fileTypes[$index]+"fileTypeMenu");
- }
- break;
- case 2 :
- if (`translator -q -ws $fileTypes[$index]`) {
- switch ($fileTypes[$index]) {
- // only 2 possible choices.
- case "mayaAscii" :
- case "mayaPLE" :
- case "mayaBinary" :
- menuItem -l $fileTypes[$index]
- ($fileTypes[$index]+"fileTypeMenu");
- break;
- }
- }
- break;
- }
- }
- }
-
- global proc int launchViewer ()
- {
- string $action = "";
- string $type = "";
- return launchViewerNew ( $action, $type );
- }
-
- global proc int launchViewerNew ( string $action, string $type )
- //
- // Description:
- // The viewer for the file dialog.
- //
- {
- global int $gv_browserMode;
-
- string $fileTypes[];
- int $index;
- int $numTypes;
- string $filePath;
- int $numWS;
- string $workspaces[];
- string $workspacePaths[];
- string $localWSName;
- string $wsForm;
- string $wsViewer;
- string $wsViewerForm;
- string $fileTypeLayout;
- string $fileTypeLabel, $fileTypeFeedback, $fileTypeOptionMenu;
-
- // Replacing -lw & -lfw with -sn & -fn. -rams
- //
- $str = `workspace -q -sn`; // Get workspace short names.
- $workspaces[0] = $str;
- $str = `workspace -q -fn`; // Get workspace full names.
- $workspacePaths[0] = $str;
-
- $localWSName = $workspaces[0]; // There is always 1 workspace.
-
- $numWS = size($workspaces);
-
- window -title "Save As"
- -menuBar true
- -rtf false -wh 450 510
- -retain
- projectViewerWindow;
-
- sv_Menu("projectViewerWindow");
-
- // Setup the local workspace.
- //
-
- // Use the workspace index to name the objects.
- $wsViewer = "wsIconViewer0";
- $wsForm = "wsForm0";
- $wsViewerForm = "wsViewerForm0";
-
- formLayout $wsForm;
-
- // Use a form layout instead of a row layout. Does a
- // better job of resizing correctly. Also helps fix the
- // Linux/Motif 2.1 problem with the option menu sometimes
- // shrinking to an unusable size.
- // -bwk 29.Nov.01
- //
- $fileTypeLayout = `formLayout`;
-
- $fileTypeLabel = `text -label "File Type:" fileTypeLabel`;
- $fileTypeFeedback = `text -label "" fileTypeFeedback`;
-
- if ($gv_browserMode == 0 || $gv_browserMode == 4) {
- $fileTypeOptionMenu = `optionMenu -label "Read As:"
- -changeCommand "sv_newFileType"
- fileTypePopList`;
- if ( $gv_browserMode != 4 ) {
- menuItem -label "Best Guess" "AnyfileTypeMenu";
- }
- } else {
- $fileTypeOptionMenu = `optionMenu -label "Write As:"
- -changeCommand "sv_newFileType"
- fileTypePopList`;
- }
-
- formLayout -edit
- -attachForm $fileTypeLabel "top" 0
- -attachForm $fileTypeLabel "left" 0
- -attachForm $fileTypeLabel "bottom" 0
- -attachNone $fileTypeLabel "right"
-
- -attachForm $fileTypeFeedback "top" 0
- -attachControl $fileTypeFeedback "left" 0 $fileTypeLabel
- -attachForm $fileTypeFeedback "bottom" 0
- -attachNone $fileTypeFeedback "right"
-
- -attachForm $fileTypeOptionMenu "top" 0
- -attachNone $fileTypeOptionMenu "left"
- -attachForm $fileTypeOptionMenu "bottom" 0
- -attachForm $fileTypeOptionMenu "right" 0
- $fileTypeLayout;
-
- buildFileTypeMenu( $gv_browserMode, $type);
-
- setParent $wsForm;
- // For centering the bottom buttons
- int $numDivisions = 100;
- formLayout -nd $numDivisions controlArea;
-
- setParent $wsForm;
-
- // Create the viewers for the various workspaces.
- //
- tabLayout -tv false -cc "pv_selectTab" workspaceTabs;
- for ($index = 0; $index < $numWS; $index++) {
- $wsViewerForm = "wsViewerForm"+$index;
-
- formLayout $wsViewerForm;
- // The layout control is supplied when drawn.
-
- tabLayout -e -tl $wsViewerForm $workspaces[$index] workspaceTabs;
-
- setParent workspaceTabs;
- }
-
- setParent $wsForm;
- formLayout -edit
- -attachForm $fileTypeLayout "top" 0
- -attachForm $fileTypeLayout "left" 5
- -attachNone $fileTypeLayout "bottom"
- -attachForm $fileTypeLayout "right" 5
-
- -attachControl workspaceTabs "top" 5 $fileTypeLayout
- -attachForm workspaceTabs "right" 5
- -attachForm workspaceTabs "left" 5
- -attachControl workspaceTabs "bottom" 5 controlArea
-
- -attachNone controlArea "top"
- -attachForm controlArea "left" 5
- -attachForm controlArea "right" 5
- -attachForm controlArea "bottom" 5
- $wsForm;
-
- return 1;
- }
-
- global proc int fileBrowser ( string $callBack, string $action, string $type,
- int $mode)
- //
- // Description:
- // This is the main for the projectViewer.
- //
- // Parameters:
- // $callBack - the global callback to be invoked when the action
- // button is pressed.
- // $action - the title for the action button.
- // $type - the file type to be highlited in the type
- // selection menu.
- // $mode - 0 for read, 1 for write.
- // 2 for write-segmented (no paths)
- // 4 give directories meaning on action.
- //
- {
- global int $gv_displayMode;
- global int $gv_displayHiddenMode;
- global string $gv_CallBackCommand;
- global int $gv_browserMode;
- global string $gv_operationMode;
- global string $gDefaultFileBrowserDir;
-
- string $wsNames[];
-
- // Check for short names
- // These are being phased out of the UI, but we'll
- // strip out the 100 in case there are scripts around
- // which use it still.
- int $catch_oldShortNames = int($mode/100);
- $mode = $mode - 100 * $catch_oldShortNames;
-
- $gv_browserMode = $mode;
-
- if (`about -evalVersion` && $mode != 0) {
- if ($type == "mayaBinary" || $type == "mayaAscii") {
- // switch the file type to ple since ascii and binary are not
- // supported in the personal learning edition
- //
- $type = "mayaPLE";
- }
- }
-
- // Override the default directory if global variable is set
- if(size($gDefaultFileBrowserDir) > 0) {
- workspace -dir $gDefaultFileBrowserDir;
- }
-
- if (`about -nt` || `about -mac`) {
- string $workspace = `workspace -q -fn`;
- // note globals do NOT get set
- fileBrowserDialog -fc $callBack -m $mode -ft $type
- -an $action -om $gv_operationMode -in $workspace;
- // previous call blocks
- $gv_operationMode="";
- return 1;
- }
-
- if (`window -exists projectViewerWindow`) {
-
- // Hide the window to do cosmetics.
- window -e -vis false projectViewerWindow;
-
- if (`formLayout -ex WSeditForm`) {
- menuItem -e -cb false viewWorkspaceEdit;
- deleteUI WSeditForm;
- }
-
- //
- // Rebuild the popdown list because the translator list might have
- // changed.
- //
- string $typeList[] = `optionMenu -q -ill fileTypePopList`;
- int $index;
- int $count;
-
- // Before deleting all the menu items create a temporary
- // dummy menu item. This fixes the problem on Linux/Motif 2.1
- // where the option menu sometimes shrinks to an unusable
- // size. The option menu widget is not very good at determining
- // it's size when it has no menu items. Motif 2.1 seems
- // to have more difficulty with this than Motif 1.2.
- //
- // Note also that an arbitrary label string is required,
- // otherwise Motif 2.1 will still have trouble figuring out
- // the option menu's proper size.
- //
- string $dummyItem = `menuItem -parent fileTypePopList -label "Bogus"`;
-
- // Delete all the old menu items in the popup menu.
- //
- $count = size($typeList);
- for ($index = 0; $index < $count; $index++) {
- deleteUI -menuItem $typeList[$index];
- }
-
- setParent -menu fileTypePopList;
-
- if ($gv_browserMode == 0 || $gv_browserMode == 4) {
- optionMenu -edit -label "Read As:" fileTypePopList;
- if ( $gv_browserMode != 4 )
- menuItem -label "Best Guess" "AnyfileTypeMenu";
- } else {
- optionMenu -edit -label "Write As:" fileTypePopList;
- }
-
- // Set the correct label based on the file operation.
- //
- buildFileTypeMenu( $gv_browserMode, $type );
-
- // Delete the temporary menu item now that the option menu
- // contains all the new file type items.
- //
- deleteUI -menuItem $dummyItem;
-
- optionMenu -e -select 1 fileTypePopList;
- if (`window -q -i projectViewerWindow`) { // If window iconic.
- window -e -i false projectViewerWindow; // restore window.
- }
-
- } else {
- if (`optionVar -ex fileBrowserDisplayMode`) {
- $gv_displayMode = `optionVar -q fileBrowserDisplayMode`;
- } else {
- // $gv_displayMode = 0;
- $gv_displayMode = 10;
- }
-
- if (`optionVar -ex fileBrowserDisplayHiddenMode`) {
- $gv_displayHiddenMode = `optionVar -q fileBrowserDisplayHiddenMode`;
- } else {
- $gv_displayHiddenMode = 0;
- }
-
- launchViewerNew ($action, $type);
- buildControlArea "controlArea";
- }
-
- $str = `workspace -q -sn`; // Replacing -lw with -sn. -rams
- $wsNames[0] = $str;
-
- window -e
- -t ($action + " ("+$wsNames[0]+")")
- -iconName $action projectViewerWindow;
-
- // Special case: when the mode is "save as", the action button
- // should say "save"
- //
- if ( $action == "Save As" ) $action = "Save";
-
-
- if ($gv_browserMode == 4) {
- button -e -l $action -align "center" -w 110
- -c ("pv_doubleClickAction 0") actionOK;
- } else {
- button -e -l $action -align "center" -w 110
- -c ("pv_doubleClickAction 1") actionOK;
- }
-
- if ($gv_operationMode == "") {
- // There is no options.
- menuItem -e -l "No Options" -c "" fileOptionsMenuItem;
- } else {
- menuItem -e -l "Options..."
- -c ("{global string $gv_operationMode;"+
- " window -e -vis false projectViewerWindow;"+
- " fileOptions $gv_operationMode (\"projectViewer \"+$gv_operationMode);"+
- " $gv_operationMode = \"\";}") fileOptionsMenuItem;
-
-
- }
-
- pv_setMenuFileType($type, 1);
- $gv_CallBackCommand = $callBack;
-
- pv_redrawView;
-
- showWindow projectViewerWindow;
-
- if (`saveImage -ex fo_saveIcon`) {
- saveImage -e -cv fo_saveIcon; // Update with current view.
- }
-
- return 1;
- }
-